<?php

class ctrl_mqManage extends L {

    /**
     * 描述 : MQ管理展示页面
     * 作者 : xuzekai
     */
    public function index() {
        $this->view->title = "消息队列管理";
        $this->view->_pagingHtml = $this->paging();
        $this->display('/html/mqManage.html');
    }

    /**
     * 描述 : 消息队列分页类
     * 作者 : xuzekai
     */
    public function paging(&$params = array()) {
        isset($params['search']) || $params['search'] = array();
        $sql = self::searchSql($params['search']);
        $config = array(
            '消息唯一ID' => '{`msgId`}',
            '消息键' => '{`type`}',
            '队列数据' => array(
                '_attr' => array(
                    'body' => '<textarea cols="40" rows="5">{`data`}</textarea>',
                ),  
            ),
            '已同步次数' => array(
                '_attr' => array(
                    'body' => '{`syncCount`}',
                    'sort' => '`syncCount`'
                )
            ),
            '最后更新时间' => array(
                '_attr' => array(
                    'body' => '{`updateTime`}',
                    'sort' => '`updateTime`'
                )
            ),
            '消息创建时间' => array(
                '_attr' => array(
                    'body' => '{`createTime`}',
                    'sort' => '`createTime`'
                )
            ),
            '同步等级' => array(
                '_attr' => array(
                    'body' => '{`syncLevel`}',
                    'sort' => '`syncLevel`'
                )
            ),
            '锁定时间' => array(
                '_attr' => array(
                    'body' => '{`lockTime`}',
                    'sort' => 'lockTime'
                )
            ),
            '_attr' => array(
                'attr' => array(
                    'table' => 'id="mqPaging" class="table table-hover table-striped table-scroll jsHoverDetails textC"'
                ),
                'data' => &$sql,
                'params' => &$params,
                'method' => __METHOD__,
            )
        );
        return of_base_com_com::paging($config);
    }

    /**
     * 描述 : 搜索SQL语句
     * 作者 : xuzekai
     */
    public static function searchSql($params) {
        $sql = "SELECT
            `type`,`msgId`,`data`,`syncCount`,`updateTime`,
            `createTime`,`syncLevel`,`lockTime`
        FROM
            `_of_com_mq`
        WHERE
            1 = 1";
        !empty($params['msgId']) && $sql .= " AND `msgId` = '{$params['msgId']}'";
        !empty($params['type']) && $sql .= " AND `type` LIKE '%{$params['type']}%'";
        !empty($params['data']) && $sql .= " AND `data` LIKE '%{$params['data']}%'"; 
        return $sql;
    }
    
}

return true;